package com.WaVel.controller.admin;

import com.Emplyment.dto.StudyPathDto;
import com.Emplyment.result.Result;
import com.Emplyment.vo.StudyPathVo;
import com.WaVel.service.StudyRouteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/study")
@Slf4j
public class StudyRouteController {

    @Autowired
    private StudyRouteService studyRouteService;

    @GetMapping("/getStudies")
    public Result<List<StudyPathVo>> getAllStudies() {
        List<StudyPathVo> allStudies = studyRouteService.getAllStudies();
        log.info("All 学习路线为: " + allStudies);
        return Result.success(allStudies);
    }

    @PostMapping("/insertStudies")
    public Result insertStudies(@RequestBody StudyPathDto studyPathDto) {
        log.info("插入学习线: " + studyPathDto);
        studyRouteService.addStudy(studyPathDto);
        return Result.success();
    }

    @PutMapping("/updateStudies")
    public Result updateStudies(@RequestBody StudyPathDto studyPathDto) {
        log.info("更新学习线: " + studyPathDto);
        studyRouteService.updateStudy(studyPathDto);
        return Result.success();
    }

    @DeleteMapping("/deleteStudies/{id}")
    public Result deleteStudies(@PathVariable("id") int id) {
        log.info("删除学习线id: " + id);
        studyRouteService.deleteStudy(id);
        return Result.success();
    }

}
